package com.onesports.intelligent.k12.polarlight.controller.operation.course;

import cn.oneframework.common.utils.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseClassifySaveOrUpdateDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseSubLevelSaveOrUpdateDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.page.PageNameDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseClassificationVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseClassifyVO;
import com.onesports.intelligent.k12.polarlight.service.course.CourseClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author FPH
 * @since 2022年7月8日10:48:38
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "运营端-基础数据配置-课程分类")
@RequestMapping(ApiPathConstants.ORG_COURSE_CLASSIFY)
@PreAuthorize("isAuthenticated()")
public class CourseClassificationController {
    private final CourseClassificationService courseClassificationService;

    @ApiOperation("查询列表")
    @PostMapping(value = "list")
    public IPage<CourseClassificationVO> queryList(@RequestBody @Valid PageNameDTO dto){
        return courseClassificationService.getClassificationList(dto.getPage(),dto.getRow(),dto.getName());
    }

    @ApiOperation("获取课程分类下拉")
    @GetMapping(value = "classify-list")
    public ResponseEntity<List<CourseClassifyVO>> queryClassifyList(){
        return ResultUtil.success(courseClassificationService.queryClassifyNameList());
    }

    @ApiOperation("分类分阶通用删除接口")
    @PostMapping("remove")
    public ResponseEntity<String> remove(String id){
        return courseClassificationService.remove(id)?ResultUtil.success("删除成功"):ResultUtil.success("删除失败");
    }

    @ApiOperation("课程分类新增修改通用接口")
    @PostMapping("classify-save-or-update")
    public ResponseEntity<String> classifySaveOrUpdate(@RequestBody @Valid CourseClassifySaveOrUpdateDTO dto){
        return courseClassificationService.classifySaveOrUpdate(dto)?ResultUtil.success("操作成功"):ResultUtil.success("操作失败");
    }

    @ApiOperation("课程分阶新增修改通用接口")
    @PostMapping("sub-level-save-or-update")
    public ResponseEntity<String> subLevelSaveOrUpdate(@RequestBody @Valid CourseSubLevelSaveOrUpdateDTO dto){
        return courseClassificationService.subLevelSaveOrUpdate(dto)?ResultUtil.success("操作成功"):ResultUtil.success("操作失败");
    }
}
